﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;

namespace LCA.Community.DAL.Model
{
    /// <summary>
    /// This class represents the vote for an answer from a specific user
    /// 
    /// RowKey = The answer ID concatenate with user ID
    /// PartitionKey = The answer ID
    /// </summary>
    public class AnswerVote : BasicDataModel
    {
        #region Fields
        private int _value; 
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="AnswerVote"/> class.
        /// </summary>
        public AnswerVote()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AnswerVote"/> class.
        /// </summary>
        /// <param name="post">The id.</param>
        /// <param name="author">The author.</param>
        /// <param name="value">The value.</param>
        public AnswerVote(string post, string author, int value)
        {
            this.RowKey = string.Concat(post,author);
            this.PartitionKey = post;
            this.Value = value;
            Author = author;
        }

        /// <summary>
        /// Gets or sets the author.
        /// </summary>
        /// <value>The author.</value>
        public string Author { get; set; }
        /// <summary>
        /// Gets or sets the post.
        /// </summary>
        /// <value>The post.</value>
        public string Post
        {
            get
            {
                return PartitionKey;
            }
            set
            {
                PartitionKey = value;
            }
        }
        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public int Value 
        { 
            get
            {
                return _value;
            }
            set
            {
                if(value != 1 && value != -1)
                {
                    throw new ArgumentException("El valor debe ser 1 o -1");
                }
                this._value = value;
            } 
        }
    }
}
